package com.ruoyi.web.wuchuan.util;//package com.ruoyi.web.wuchuan.util;
//
//
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import freemarker.template.Configuration;
//import freemarker.template.Template;
//import org.geotools.data.shapefile.ShapefileDataStore;
//import org.geotools.data.simple.SimpleFeatureCollection;
//import org.geotools.data.simple.SimpleFeatureIterator;
//import org.geotools.data.simple.SimpleFeatureSource;
//import org.geotools.geojson.feature.FeatureJSON;
//import org.opengis.feature.simple.SimpleFeature;
//import sun.misc.BASE64Encoder;
//
//import java.io.*;
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
//import java.time.LocalDate;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author by shixd
// * @date 2021/3/26
// * @desc
// */
//public class wordUtil {
//    /**
//     * shp转换为Geojson
//     * @param shpPath
//     * @return
//     */
//    public Map shape2Geojson(String shpPath, String jsonPath){
//        Map map = new HashMap();
//
//        FeatureJSON fjson = new FeatureJSON();
//
//        try{
//            StringBuffer sb = new StringBuffer();
//            sb.append("{\"type\": \"FeatureCollection\",\"features\": ");
//
//            File file = new File(shpPath);
//            ShapefileDataStore shpDataStore = null;
//
//            shpDataStore = new ShapefileDataStore(file.toURL());
//            //设置编码
//            Charset charset = Charset.forName("GBK");
//            shpDataStore.setCharset(charset);
//            String typeName = shpDataStore.getTypeNames()[0];
//            SimpleFeatureSource featureSource = null;
//            featureSource =  shpDataStore.getFeatureSource (typeName);
//            SimpleFeatureCollection result = featureSource.getFeatures();
//            SimpleFeatureIterator itertor = result.features();
//            JSONArray array = new JSONArray();
//            while (itertor.hasNext())
//            {
//                SimpleFeature feature = itertor.next();
//                StringWriter writer = new StringWriter();
//                fjson.writeFeature(feature, writer);
//                JSONObject json = new JSONObject(writer.toString());
//                array.put(json);
//            }
//            itertor.close();
//            sb.append(array.toString());
//            sb.append("}");
//
//            //写入文件
//            cm.append2File(jsonPath, sb.toString());
//
//            map.put("status", "success");
//            map.put("message", sb.toString());
//        }
//        catch(Exception e){
//            map.put("status", "failure");
//            map.put("message", e.getMessage());
//            e.printStackTrace();
//
//        }
//        return map;
//    }
//
//    /**
//     * 工具类测试方法
//     * @param args
//     */
//    public static void main(String[] args){
//        FileFormat fileFormat = new FileFormat();
//        long start = System.currentTimeMillis();
//        String shpPath = "/Users/lzugis/Documents/chinadata/cityboundry.shp";
//        String jsonPath = "/Users/lzugis/Documents/chinadata/cityboundry.geojson";
//        Map map = fileFormat.shape2Geojson(shpPath, jsonPath);
//
////		String shpPath = "D:/data/beijing/China43262.shp";
////		String jsonPath = "D:/data/beijing/China4326.geojson";
////		Map map = fileFormat.geojson2Shape(jsonPath, shpPath);
//
//        System.out.println(jsonPath+",共耗时"+(System.currentTimeMillis() - start)+"ms");
//    }
//
//}
